//
//  TableShowBtnCellModel.swift
//  CooperSwift
//
//  Created by 计海峰 on 2022/1/17.
//

import Foundation
import UIKit
import RxSwift

// MARK: - btn cell config
public class TableShowBtnCellModel : NSObject, PublicTableCellConfigProtocol, BindKeyProtocol  {
    
    public typealias TargetType = [UIButton]
    
    let bag = DisposeBag()
    
    /// 默认
    public var model: Any?
    
    //  MARK: - 基础实现
    required public init(_ model: Any?) {
        self.model = model
    }
    
    public func cellCls() -> UITableViewCell.Type {
        return TableShowBtnCell.self
    }
    
    // MARK: - 执行
    public func once(_ btns: [UIButton], cell: UITableViewCell) {
//        self.cellHeightSubject.distinctUntilChanged().skip(1).debounce(.milliseconds(200), scheduler: MainScheduler.instance).subscribe(onNext: {
//            self.cellHeight = $0
//            self.postTableService(.reloadCell)
//        }).disposed(by: bag)
    }
    
    @MainActor public func every(_ btns: [UIButton], cell: UITableViewCell) {
        btns.forEach { $0.isHidden = true }
        if let btnControl = self.model as? ViewControlProtocol {
            btnControl.loadAll(btns.first!, judgeType: true)
            return
        }
        if let btnControls = self.model as? [ViewControlProtocol] {
            for (index, control) in btnControls.enumerated() {
                control.loadAll(btns[index], judgeType: true)
            }
            return
        }
    }
    
}
